<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="套餐销售明细">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }
    </style>

    <script>
        jQuery(function () {
            fixTableOperatorButton();

            ajaxSelect("${baseUrl}organization/store/getStores.action","storeId","全部");
            ajaxSelect("${baseUrl}user/user/getAll.action.action",'userId',"全部");
        });

        layui.use(['form', 'table','laydate'], function () {
            let $ = layui.jquery,
                form = layui.form,
                laydate = layui.laydate,
                table = layui.table,
                util = layui.util;
            laydate.render({
                elem: '#date1'
            });
            laydate.render({
                elem: '#date2'
            });

            renderTable();

            form.on('submit(search)', function (data) {
                let json = data.field;
                table.reload('table',{
                    where: json
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            });

        });


        function renderTable() {
            $("#searchForm")[0].reset();
            layui.table.render({
                id:'table',
                elem: '#table',
                url: "${baseUrl}marketGoods/goodsPacket/getSaleListById.action",
                totalRow:true,
                where : {
                    packetId:"${id}",
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {width:70,title:"序号",templet:function (d) {
                            return genTableIndex(d.close, "作废", d);
                        }},
                    {width: 100, title: '业务日期',style:"font-size:12px;",templet: function (d) {
                            return GMTToDate(d.date);
                        }},
                    {field: 'no', width: 130, title: '单据编号',style:"font-size:12px;",templet:'#noBar'},
                    {field: 'customName',width: 120, title: '客户',style:"font-size:12px;"},
                    {field: 'storeName',width: 120, title: '销售门店',style:"font-size:12px;"},
                    {field:'number', width: 70, title: '数量',style:"font-size:12px;", templet: function(d){
                            return getNumber(d.number);
                        }},
                    {field:'price',width: 90, title: '单价',style:"font-size:12px;",templet: function (d) {
                            return getPrice(d.price);
                        }},
                    {field:'amount',width: 90, title: '金额',style:"font-size:12px;",templet: function (d) {
                            return getPrice(d.amount);
                        }},
                    {field: 'userName', width: 120, title: '经手人',style:"font-size:12px;"},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){

                    let amount = 0;
                    let number = 0;
                    $.each(res.data, function (i,d) {
                        if (d.close) {
                            return true;
                        }
                        amount += parseFloat(d.amount);
                        number += d.number;
                    });

                    setTotalRow("number",getNumber(number));
                    setTotalRow("amount",getPrice(amount));
                    setTotalRow("0","合计");


                    setTableLineCss("table",res.data, "close", true, "font-gray-c2c2c2");

                    $(".no").unbind().bind("click", function () {
                        openTab($(this).attr("title"), $(this).attr("url"));
                    });
                }
            });
        }
    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" id="searchForm">
            <div class="layui-form-item">


                <div class="layui-inline">
                    <label class="layui-form-label">搜索信息</label>
                    <div class="layui-input-inline">
                        <input type="text" name="search" style="font-size: 12px;" placeholder="编号、客户" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <a class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon layui-icon-search"></i></a>
                    <a class="layui-btn " id="selectSearch">筛选</a>
                </div>

                <div class="table-tool-div-screen" status="close" style="display: none">


                    <div class="layui-inline">
                        <label class="layui-form-label">业务日期</label>
                        <div class="layui-input-inline">
                            <input type="text" name="date1" id="date1" lay-verify="date1" placeholder="开始日期" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" name="date2" id="date2" lay-verify="date2" placeholder="结束日期" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline" >
                        <label class="layui-form-label">门店</label>
                        <div class="layui-input-inline">
                            <select name="storeId"></select>
                        </div>
                    </div>

                    <div class="layui-inline" >
                        <label class="layui-form-label">经手人</label>
                        <div class="layui-input-inline">
                            <select name="userId"></select>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <a class="layui-btn" lay-submit="" lay-filter="search">搜索</a>
                        <a class="layui-btn layui-btn-primary" id="clearSearch">清空所有条件</a>
                    </div>
                </div>
                <script>
                    $("#selectSearch").click(function () {
                        if ($(".table-tool-div-screen").attr("status")=="close") {
                            $(".table-tool-div-screen").css("display","block");
                            $(".table-tool-div-screen").attr("status","open");
                            $("#search").parent().parent().css("display","none");
                            $("#search").val("");
                            $("#btn-search").css("display","none");
                            $(this).html("收起");
                        } else {
                            $(".table-tool-div-screen").css("display","none");
                            $(".table-tool-div-screen").attr("status","close");
                            $("#search").parent().parent().css("display","inline-block");
                            $("#btn-search").css("display","inline-block");
                            $(this).html("筛选");
                        }
                    });

                    $("#clearSearch").click(function () {
                        $("#searchForm")[0].reset();
                    });
                </script>

            </div>
        </form>
        <hr/>

        <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>
    </div>
</div>
</body>

<script type="text/html" id="noBar">
    {{# if(d.type==1){ }}
    <a href="#" class="no" title="销售单详情" url="${baseUrl}sale/saleDetail.action?id={{d.id}}">{{d.no}}</a>
    {{# } else { }}
    <a href="#" class="no" title="销售退货单详情" url="${baseUrl}sale/refundDetail.action?id={{d.id}}">{{d.no}}</a>
    {{# } }}
</script>

<html:loading/>
</html>